<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>试卷查询</title>
<link rel="stylesheet" href="<%=request.getContextPath()%>/static/sys/user/css/user-list.css"/>
<link rel="stylesheet" href="${pageContext.request.contextPath}/static/common/plugin/tree/css/demo.css" type="text/css"/>
<link rel="stylesheet" href="${pageContext.request.contextPath}/static/common/plugin/tree/css/tree.css" type="text/css"/>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/common/plugin/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/common/plugin/tree/js/jquery.ztree.core.js"></script>
</head>
<body>
	
<form id="myform1" name="myform1" action = "<%=request.getContextPath()%>/teach/testpaper/TestPaperServlet?command=list" method="post">
   试卷名称：<input type="text" name="name" value="${conditionEntity.name}"></input>&nbsp;
   课程名称：<select name="courseName">
       <option value="">--请选择--</option>
      	 <c:forEach items="${conditionEntity.courseNameList }" var="testPaper">
      	  <option value="${testPaper }"<c:if test="${conditionEntity.courseName eq testPaper }">selected=selected</c:if>>${testPaper}</option>
      	 </c:forEach>
         </select>
   状态：<select name="state">
			<option value="0">-全部-</option>
			<option value="1" <c:if test="${conditionEntity.state == 1}">selected=selected</c:if>>有效</option>
			<option value="2" <c:if test="${conditionEntity.state == 2}">selected=selected</c:if>>无效</option>
		</select>
      <button>查询</button>
      <a href="<%=request.getContextPath()%>/teach/testpaper/TestPaperServlet?command=prePaperAdd">试卷新增</a>
   </form>
<%--表格形式显示数据 --%>
<table width="100%" border="1" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="30">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="24" bgcolor="#353c44">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="6%" height="19" valign="bottom"><div align="center"><img src="<%=request.getContextPath()%>/static/common/basic-page/images/tb.gif" width="14" height="14" /></div></td>
                <td width="94%" valign="bottom"><span class="STYLE1"> </span></td>
              </tr>
            </table></td>
            <td><div align="right"><span class="STYLE1">
              <input type="checkbox" name="checkbox11" id="checkbox11" />
              全选      &nbsp;&nbsp;<img src="<%=request.getContextPath()%>/static/common/basic-page/images/add.gif" width="10" height="10" /> 添加   &nbsp; <img src="<%=request.getContextPath()%>/static/common/basic-page/images/del.gif" width="10" height="10" /> 删除    &nbsp;&nbsp;<img src="<%=request.getContextPath()%>/static/common/basic-page/images/edit.gif" width="10" height="10" /> 编辑   &nbsp;</span><span class="STYLE1"> &nbsp;</span></div></td>
          </tr>
        </table>
        </td>
      </tr>
    </table>
    </td>
	</tr>
	<tr>
		<td>
			<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#a8c7ce">
				<thead>
					<tr>
						<th width="4%" height="20" bgcolor="d3eaef" class="STYLE10">
						<div align="center">
							<input type="checkbox" name="checkbox" id="checkbox" />
						</div>
						<td height="20" bgcolor="d3eaef" class="STYLE19"><div align="center"><span class="STYLE10">序号</span></div></td>
						<td height="20" bgcolor="d3eaef" class="STYLE19"><div align="center"><span class="STYLE10">试卷名称</span></div></td>
						<td height="20" bgcolor="d3eaef" class="STYLE19"><div align="center"><span class="STYLE10">所属课程</span></div></td>
						<td height="20" bgcolor="d3eaef" class="STYLE19"><div align="center"><span class="STYLE10">总分分数</span></div></td>
						<td height="20" bgcolor="d3eaef" class="STYLE19"><div align="center"><span class="STYLE10">通过分数</span></div></td>
						<td height="20" bgcolor="d3eaef" class="STYLE19"><div align="center"><span class="STYLE10">总分数</span></div></td>
						<td height="20" bgcolor="d3eaef" class="STYLE19"><div align="center"><span class="STYLE10">状态</span></div></td>
						<td height="20" bgcolor="d3eaef" class="STYLE19"><div align="center"><span class="STYLE10">操作</span></div></td>
					</tr>
				</thead>
				<tbody>
				<c:forEach items="${pageModel.list}" var="paper"  varStatus="v">
							<tr>
							<td height="20" bgcolor="#FFFFFF"><div align="center">
						          <input type="checkbox" name="checkbox4" id="checkbox4" />
						    </div></td>
							<td height="20" bgcolor="d3eaef" class="STYLE21" scope="row"> ${v.count+(pageModel.pageNo-1)*pageModel.pageSize} </td>
							<td height="20" bgcolor="d3eaef" class="STYLE21">${paper.name }</td>
							<td height="20" bgcolor="d3eaef" class="STYLE21">${paper.courseName}</td>
							<td height="20" bgcolor="d3eaef" class="STYLE21">${paper.totalPoint }</td>
							<td height="20" bgcolor="d3eaef" class="STYLE21">${paper.passPoint }</td>
							<td height="20" bgcolor="d3eaef" class="STYLE21">${paper.totalMinutes }</td>
							<td height="20" bgcolor="d3eaef" class="STYLE19" align="center" id="state${v.count}"><c:if test="${paper.state == 1 }">
						<font color="green" id="state${paper.id}">有效</font>
					</c:if> <c:if test="${paper.state == 2 }">
						<font color="red" id="state${paper.id}">无效</font>
					</c:if></td>
							<td height="20" bgcolor="d3eaef" class="STYLE21" align="center">
							<a href="<%=request.getContextPath()%>/teach/testpaper/TestPaperServlet?command=detail&id=${paper.id }">详情|</a>
							<a href="<%=request.getContextPath()%>/qes/QesPaperServlet?command=preview&id=${paper.id }&name=${paper.name}">试卷预览|</a>
							<a href="<%=request.getContextPath()%>/qes/QesPaperServlet?command=buildpaper&id=${paper.id }">重新生成|</a>
							<a id="changeState${v.count }" href="javascript:;" 
						    onclick ="updateState(${v.count}, ${paper.id});"> 
							<c:if test="${paper.state == 1 }">无效</c:if> 
							<c:if test="${paper.state == 2 }">有效</c:if>
					        </a>
							</td>
					</tr> 
				</c:forEach>
				<tr>
         <td colspan="9" align="right">
          <a href="javascript:submitCondition(${ pageModel.first})">首页</a>
          <a href="javascript:submitCondition(${ pageModel.pre})">上一页</a>
                    第<select  onchange="goPage(this)">
	       <script>
			       var pageNo = '${pageModel.pageNo }';
				   var totalPage = '${pageModel.totalPage }';
				   for (var i = 1; i <= totalPage; i++) {
					if (pageNo == i) {
						document.write('<option value="' + i + '" selected="selected">' + i + '</option>');
					} else {
						document.write('<option value="' + i + '">' + i + '</option>');
					}
			}
	       </script>
       </select>页
	         ,共${pageModel.totalPage }页
	          <a href="javascript:submitCondition(${ pageModel.next})">下一页</a>
	          <a href="javascript:submitCondition(${ pageModel.last})">尾页 </a>
	                   共 ${pageModel.allRecords }张试卷
	       </td>
  </tr>
  </table>
  </table>
</body>
<script type="text/javascript">
function submitCondition(pageNo){
	document.myform1.action="<%=request.getContextPath()%>/teach/testpaper/TestPaperServlet?command=list&pageNo="+pageNo;
	document.myform1.submit();
}

function goPage(obj){
	submitCondition(obj.value);
 }
	function updateState(count,id){
		var xmlhttp;
		if (window.XMLHttpRequest)
		  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		xmlhttp.onreadystatechange=function()
		  {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		    {
			  var state=xmlhttp.responseText;
			  
			  var stateId = document.getElementById("state"+count);
			  var changeStateId = document.getElementById("changeState"+count);

			  if(state==1){
				  stateId.innerHTML = "有效";
				  changeStateId.innerHTML = "无效";
			  }else if(state==2){
				  stateId.innerHTML = "无效";
				  changeStateId.innerHTML = "有效";
			  }
			  
		    }
		  }
		xmlhttp.open("post","<%=request.getContextPath()%>/teach/testpaper/TestPaperServlet?command=changeState&id="+id,true);
		xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		xmlhttp.send();
	}
</script>
<SCRIPT type="text/javascript">
		var setting = {
			// 配置基本信息
			data: {
				simpleData: {
					enable: true
				}
			},
			// 回调处理处理函数配置
			callback: {
				onClick: onClick
			}
		};

		
		// 定义单击树形节点的回调函数
		function onClick(event, treeId, treeNode) {
			alert(treeNode.id);
		}


		$(document).ready(function(){
			var zNodes;
			$.get("${pageContext.request.contextPath}/teach/testpaper/TestPaperServlet?command=list",function(data) {
				zNodes = eval("("+data+")");
				$.fn.zTree.init($("#treeDemo"), setting, zNodes);
			});
		});
	</SCRIPT>
</html>
